package com.wyd.sort;

import java.util.Arrays;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {

    public static  void test(SortInterface sortInterface){

        System.out.println(sortInterface.getClass().getName());

        int[] testSizes = new int[]{10, 1000, 10000, 10000 * 10, 10000 * 100};

        for (int size : testSizes) {
            int[] testdata = new int[size];
            for (int i = 0; i < size; i++) {
                testdata[i] = (int) (Math.random() * 1000);
            }
            int[] arrCopyt = Arrays.copyOf(testdata, testdata.length);
            int[] arrCopyt1 = Arrays.copyOf(testdata, testdata.length);

            long start = System.currentTimeMillis();
            int[] res1 = sortInterface.sort(testdata);
            long time = (System.currentTimeMillis() - start);

            start = System.currentTimeMillis();
            Arrays.sort(arrCopyt);
            long jdkTime = (System.currentTimeMillis() - start);

            System.out.println("数据量：" + size + " 耗时：" + time + " jdk：" + jdkTime );

            if (!Arrays.equals(res1,arrCopyt)) {
                System.out.println("错误");
                break;
            }
        }

    }
    public static  void test2(SortInterface sortInterface,SortInterface sortInterface2){

        System.out.println(sortInterface.getClass().getName());

        int[] testSizes = new int[]{10, 1000, 10000, 10000 * 10, 10000 * 50, 10000 * 100};

        for (int size : testSizes) {
            int[] testdata = new int[size];
            for (int i = 0; i < size; i++) {
                testdata[i] = (int) (Math.random() * 1000);
            }
            int[] arrCopyt = Arrays.copyOf(testdata, testdata.length);
            int[] arrCopyt1 = Arrays.copyOf(testdata, testdata.length);

            long start = System.currentTimeMillis();
            int[] res1 = sortInterface.sort(testdata);
            long time = (System.currentTimeMillis() - start);

            start = System.currentTimeMillis();
            sortInterface2.sort(arrCopyt);
            long jdkTime = (System.currentTimeMillis() - start);

            System.out.println("数据量：" + size + " 耗时：" + time + " jdk：" + jdkTime );

            if (!Arrays.equals(res1,arrCopyt)) {
                System.out.println("错误");
                break;
            }
        }

    }
    public static void main(String[] args) {
//        test( new BubbleSort());
//        test( new SelectionSort());
        test( new QuickSort());
//
//        test( new QuickSortv2());

//        test2( new InsertSort(),new SelectionSort());
    }
}